import orm
import time


# 4.显示账单（显示总支出金额，总收入金额，结余金额
# 5.写入账单（时间按照格式显示

def show_book():
    path = r'account_book.json'
    data = orm.read_book(path)
    money = 0
    expend = 0
    for a in data:
        amount = float(a["金额"])
        # print(amount)
        if amount > 0:
            money += amount
        elif amount < 0:
            expend -= amount
    print(f'总收入金额为：{money}')
    print(f'总支出金额为：{expend}')
    print(f'结余金额为：{money - expend}')


def write_bill():
    path = r'account_book.json'
    project = input('请输入项目：')
    classify = input('请输入分类：')
    money = input('请输入金额：')
    data_list = orm.read_book(path)
    new_list = {"时间": time.strftime('%Y/%m/%d %H:%M:%S'), "项目": project, "分类": classify, "金额": money}
    data_list.append(new_list)
    orm.write_data(data_list, path)
    print(data_list[-1])


if __name__ == '__main__':
    # show_book()
    write_bill()
    show_book()
